<template>
  <el-container class="my-layout">
    <el-aside width="200px">
      <img width="100%" src="@/assets/images/logo.png" alt="">
      <el-menu default-active="$route.path" background-color="#023" text-color="#fff" active-text-color="#409eff"
        style="border-right: none;" router>
        <el-menu-item index="/">
          <i class="el-icon-s-home"></i>数据概览
        </el-menu-item>
        <el-menu-item index="/article">
          <i class="el-icon-document"></i>内容管理
        </el-menu-item>
        <el-menu-item index="/publish">
          <i class="el-icon-s-promotion"></i>发布文章
        </el-menu-item>
      </el-menu>

    </el-aside>
    <el-container>
      <el-header>
        <span @click="qweRty()">{{ user.name || user.mobile }}</span>
        <el-link @click="onLogout()" :underline="false" icon="el-icon-unlock">退出</el-link>
      </el-header>
      <el-main>
        <router-view />
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import auth from '@/utils/token'
export default {
  name: 'LayoutView',
  data () {
    return {
      user: {}
    }
  },
  async created () {
    const res = await this.$http.get('/v1_0/user/profile')
    console.log(res)
    this.user = res.data.data
  },
  methods: {
    onLogout () {
      this.$confirm('确定退出吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        auth.delToken()
        this.$router.push('/login')
        this.$message.success('退出成功')
      }).catch(() => {})
    },
    qweRty () {
      this.$router.push('/appp')
    }
  }
}
</script>

<style scoped>
.my-layout {
  height: 100vh;
}

.el-aside {
  background-color: #023;
}

.el-header {
  border-bottom: 1px solid #ddd;
  display: flex;
  justify-content: end;
  align-items: center;
  background-color: white;
  gap: 10px;
}
</style>
